﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UISpinnerTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetRangeValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            var spinner = window.UITab("@AutomationId='tabControl1'").UISpinner();
            Assert.AreEqual(0, spinner.RangeValue);
        }

        [TestMethod]
        public void ShouldSetRangeValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            var spinner = window.UITab("@AutomationId='tabControl1'").UISpinner();
            spinner.RangeValue = 0; 
            Assert.AreEqual(0, spinner.RangeValue);
        }

        [TestMethod]
        public void ShouldGetIsReadyOnly()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            var spinner = window.UITab("@AutomationId='tabControl1'").UISpinner();
            Assert.IsFalse(spinner.IsRangeReadOnly);
        }

        [TestMethod]
        public void ShouldGetMinimum()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            var spinner = window.UITab("@AutomationId='tabControl1'").UISpinner();
            Assert.AreEqual(0, spinner.Minimum);
        }

        [TestMethod]
        public void ShouldGetMaximum()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            var spinner = window.UITab("@AutomationId='tabControl1'").UISpinner();
            Assert.AreEqual(0, spinner.Maximum);
        }

        [TestMethod]
        public void ShouldGetLargeChange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            var spinner = window.UITab("@AutomationId='tabControl1'").UISpinner();
            Assert.IsTrue(double.IsNaN(spinner.LargeChange));
        }

        [TestMethod]
        public void ShouldGetSmallChange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            var spinner = window.UITab("@AutomationId='tabControl1'").UISpinner();
            Assert.AreEqual(1, spinner.SmallChange);
        }

        [TestMethod]
        public void ShouldGetAllSpinners()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            List<UISpinner> spinners = window.UITab("@AutomationId='tabControl1'").UISpinners();
            Assert.AreEqual(3, spinners.Count);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}